//
//  GWNewfeatureController.m
//  新浪微博
//
//  Created by qianfeng on 16/1/12.
//  Copyright (c) 2016年 高炜. All rights reserved.
//
#define pictureNumber 4
#import "GWNewfeatureController.h"
#import "GWMainViewController.h"
@interface GWNewfeatureController ()<UIScrollViewDelegate>
@property (nonatomic,weak)UIScrollView *scrollView;
@property (nonatomic,weak) UIPageControl *pg;
@end

@implementation GWNewfeatureController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createScrollView];
    [self createPageControl];
    
    
    // Do any additional setup after loading the view.
}
-(void)createPageControl
{
    UIPageControl *pg =[[UIPageControl alloc]init];
    [self.view addSubview:pg];
    pg.frame =CGRectMake(0, self.view.height-30, self.view.width, 30);
    pg.pageIndicatorTintColor =myColor(189, 189, 189);
    pg.currentPageIndicatorTintColor =myColor(253, 98, 42);
    pg.numberOfPages =pictureNumber;
    self.pg =pg;
}
-(void)createScrollView
{
    UIScrollView *scrollView =[[UIScrollView alloc]init];
    [self.view addSubview:scrollView];
    scrollView.frame =self.view.frame;
    self.scrollView =scrollView;
    scrollView.pagingEnabled =YES;
    scrollView.delegate =self;
    CGFloat imageW =self.view.width;
    CGFloat imageH =self.view.height;
    
    scrollView.contentSize =CGSizeMake(imageW*pictureNumber, 0);
    scrollView.backgroundColor =myColor(246, 246, 246);
    scrollView.showsHorizontalScrollIndicator =NO;
    for (int i=0; i<pictureNumber; i++) {
        UIImageView *imageView =[[UIImageView alloc]init];
        imageView.frame =CGRectMake(i*imageW, 0, imageW, imageH);
        
        imageView.image =[UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%d",i+1]];
        if (i==pictureNumber-1) {
            [self createBtn:imageView];
        }
        [self.scrollView addSubview:imageView];
    }
}
-(void)createBtn:(UIImageView *)imageView
{
    imageView.userInteractionEnabled =YES;
    
    [self createStarBtn:imageView];
    [self createShareBtn:imageView];
}
-(void)createShareBtn:(UIImageView*)imageView
{
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
    btn.size =CGSizeMake(150, 30);
    btn.center =CGPointMake(imageView.width*0.5, imageView.height*0.73);
    [btn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [btn setTitle:@"分享给大家" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(shareBtnOnTouch:) forControlEvents:UIControlEventTouchUpInside];
    btn.titleEdgeInsets =UIEdgeInsetsMake(0, 10, 0, 0);
    [imageView addSubview:btn];
}
-(void)shareBtnOnTouch:(UIButton *)btn
{
    btn.selected =!btn.selected;
}
-(void)createStarBtn:(UIImageView*)imageView
{
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [btn setTitle:@"开始微博" forState:UIControlStateNormal];
    btn.size =btn.currentBackgroundImage.size;
    btn.center =CGPointMake(imageView.width*0.5, imageView.height*0.8);
    [btn addTarget:self action:@selector(starOnClick) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:btn];
}
-(void)starOnClick
{
    [UIApplication sharedApplication].keyWindow.rootViewController =[[GWMainViewController alloc]init];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.pg.currentPage =(int)((self.scrollView.contentOffset.x/self.view.width)+0.5);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
